package jvm;

import org.junit.Test;

import java.util.concurrent.locks.LockSupport;

public class JvmTest1 {
    @Test
    public void t2() {
        boolean f = false;
        for (int i = 0; i < 100; i++) {
            f = "h2".equals("h2");
        }
        long l = System.currentTimeMillis();
        for (int i = 0; i < 100000000; i++) {
            f = "h2".equals("h2");
        }
        System.out.println((System.currentTimeMillis() - l) + "ms");
    }

    @Test
    public void t3() {
        boolean f = false;
        byte a = 1;
        byte b = 2;
        long l = System.currentTimeMillis();
        for (int i = 0; i < 100000000; i++) {
            f = a == b;
        }
        System.out.println((System.currentTimeMillis() - l) + "ms");
    }

    @Test
    public void t4() {
        boolean f = false;
        int c = 1;
        int d = 2;
        long l = System.currentTimeMillis();
        for (int i = 0; i < 100000000; i++) {
            f = c == d;
        }
        System.out.println((System.currentTimeMillis() - l) + "ms");
    }

    @Test
    public void t1() {
        Thread thread = Thread.currentThread();
        LockSupport.unpark(thread);//释放许可
        LockSupport.park();// 获取许可
        System.out.println(111);

        LockSupport.unpark(thread);//释放许可
        LockSupport.unpark(thread);//释放许可
        LockSupport.park();// 获取许可
        System.out.println(222);

        LockSupport.unpark(thread);//释放许可
        LockSupport.park();// 获取许可
        LockSupport.park();// 获取许可
        System.out.println(333);
    }

    @Test
    public void t5() {
        boolean f = false;
        Object o=null;
        for (int i = 0; i < 100000000; i++) {
            if(o == null);
        }
        long l = System.nanoTime();
        for (int i = 0; i < 100000000; i++) {
            if(o == null);
        }
        System.out.println((System.nanoTime() - l) + "ns");
        for (int i = 0; i < 100000000; i++) {
            if(f);
        }
        l = System.nanoTime();
        for (int i = 0; i < 100000000; i++) {
            if(f);
        }
        System.out.println((System.nanoTime() - l) + "ns");
    }
}
